import { Redirect, Stack } from 'expo-router'
import { Text } from 'react-native'

import { useAuth } from '~/src/hooks/useAuth'

export default function AppLayout() {
  const { accessToken, loading } = useAuth()
  console.log('accessToken', accessToken)

  if (loading) {
    return <Text>loading</Text>
  }

  if (!accessToken) {
    return <Redirect href="/login" />
  }

  // This layout can be deferred because it's not the root layout.
  return (
    <Stack
      screenOptions={{
        headerShown: false,
        animation: 'default',
      }}
    />
  )
}
